package com.doit.day01;

import lombok.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

public class MyIterator implements Iterator<Hero> {
    private BufferedReader br;
    private String line;
    public MyIterator() {
        try {
            br = new BufferedReader(new FileReader("data/hero.txt"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean hasNext() {
        //打开文件，读取数据
        try {
            line = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return line != null;
    }

    @Override
    public Hero next() {
        //5,前进_200::250
        String[] arr = line.split(",");
        String id = arr[0];
        String[] arr1 = arr[1].split("_");
        String name = arr1[0];
        String[] arr2 = arr1[1].split("::");
        String faceValue = arr2[0];
        String power = arr2[1];
        return new Hero(Integer.parseInt(id),name,Integer.parseInt(faceValue),Double.parseDouble(power));
    }

}




@ToString
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
class Hero{
    private int id;
    private String name;
    private int faceValue;
    private Double power;
}
